// `Chai`: JavaScript assertion library
//   - assertions are called "matchers"
//   - `@nomicfoundation/hardhat-chai-matchers`
const { expect } = require("chai");

// The `ethers` variable is available in the global scope
// const { ethers } = require("hardhat");

describe("Token contract", function () {
  it("Deployment should assign the total supply of tokens to the owner", async function () {

    const [owner] = await ethers.getSigners();

    // Deploy a contract and return a `Promise` that resolves to a `Contract`
    const hardhatToken = await ethers.deployContract("Token");

    // All calls to contract methods are asynchronous
    const ownerBalance = await hardhatToken.balanceOf(owner.address);
    expect(await hardhatToken.totalSupply()).to.equal(ownerBalance);
  });

  it("Should transfer tokens between accounts", async function() {
    const [owner, addr1, addr2] = await ethers.getSigners();

    const hardhatToken = await ethers.deployContract("Token");

    // Transfer 50 tokens from owner to addr1
    await hardhatToken.transfer(addr1.address, 50);
    expect(await hardhatToken.balanceOf(addr1.address)).to.equal(50);

    // Use `connect()` method on ethers.js `Contract` object to connect it to
    // a different account

    // Transfer 50 tokens from addr1 to addr2
    await hardhatToken.connect(addr1).transfer(addr2.address, 50);
    expect(await hardhatToken.balanceOf(addr2.address)).to.equal(50);
  });
});